package com.artpri.action.user;

import java.util.List;

import com.artpri.action.BaseAction;
import com.artpri.model.vo.SimpleGoods;
import com.artpri.service.AttentionCenterService.AttentionType;

/**
 * 商品收藏
 * @author ZhangSi
 */
public class CollectGoodsAction extends BaseAction {

	private static final long serialVersionUID = -4460550317693053249L;

	private Integer goodsNum;
	
	private String collectName;
	
	private String picUrl;
	
	private String msg;
	
	private List<Integer> ids;
	
	private List<SimpleGoods> collects;
	
	private Integer pageNo;
	private Integer totalRecords;
	private Integer pageSize;
	
	/**
	 *	添加收藏 
	 */
	public String addCollect() throws Exception {
		Integer i = getAttentionCenterService().addGoodsCollect(getSessionUser().getUserNum(), goodsNum, collectName, picUrl);
		if (i == 1) {
			msg = "1";
		} else if (i ==2) {
			msg = "2";
		} else {
			msg = "0";
		}
		return SUCCESS;
	}
	
	/**
	 *	取消关注 
	 */
	public String deleteCollect() throws Exception {
		getAttentionCenterService().deleteGoodsCollect(ids);
		msg = SUCCESS;
		return SUCCESS;
	}

	/**
	 * 关注的商品列表
	 */
	public String listCollect() throws Exception {
		int userNum = getSessionUser().getUserNum();
		totalRecords = getAttentionCenterService().getResultCount(AttentionType.GOODS, userNum);
		collects = getAttentionCenterService().listGoodsCollectByPage(userNum, getPageNo(), pageSize);
		return SUCCESS;
	}
	
	public List<Integer> getIds() {
		return ids;
	}

	public void setIds(List<Integer> ids) {
		this.ids = ids;
	}

	public Integer getGoodsNum() {
		return goodsNum;
	}

	public void setGoodsNum(Integer goodsNum) {
		this.goodsNum = goodsNum;
	}

	public String getCollectName() {
		return collectName;
	}

	public void setCollectName(String collectName) {
		this.collectName = collectName;
	}

	public String getPicUrl() {
		return picUrl;
	}

	public void setPicUrl(String picUrl) {
		this.picUrl = picUrl;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public List<SimpleGoods> getCollects() {
		return collects;
	}

	public void setCollects(List<SimpleGoods> collects) {
		this.collects = collects;
	}

	public Integer getPageNo() {
		pageNo = pageNo == null ? 1 : pageNo;
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getTotalPage() {
		return totalRecords%pageSize==0 ? totalRecords/pageSize : totalRecords/pageSize +1;
	}

	public Integer getTotalRecords() {
		return totalRecords;
	}

	public void setTotalRecords(Integer totalRecords) {
		this.totalRecords = totalRecords;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
}
